/**
 * ======================================================
 * stats.h 
 *
 * Stat tracking
 * ======================================================
 *
 * The MIT License
 * 
 * Copyright (c) 2008 Matthew Maravillas
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * Version: $Id$
 */

#ifndef _INCLUDE_ARSSTATS_STATS_H_
#define _INCLUDE_ARSSTATS_STATS_H_

#include <vector>
#include "edict.h"
#include <ISmmPlugin.h> // Including this before edict.h gives me an error (redefining _vsnprintf)
#include <iplayerinfo.h>
#include "player.h"
#include "const.h"
#include "util.h"
#include "sendprops.h"
#include <string>

#if defined WIN32 && !defined snprintf
#define snprintf _snprintf
#endif

class Stats
{
public:
    Stats(IServerGameDLL *server, IVEngineServer *engine, IPlayerInfoManager *playerInfoManager) 
        : mServer(server), 
          mEngine(engine), 
          mPlayerInfoManager(playerInfoManager) 
    {
        mPlayers.resize(ARSSTATS_PLAYER_LIMIT); 
        DEBUG1("Stats constructed; player vector size: %d", mPlayers.size());

        mSendProps = new SendProps(mServer);
    };

    ~Stats() 
    { 
        delete mSendProps;
    };

    void AddPlayer(edict_t *edict, int entityId, int userId, const char *steamId, const char *playerName);
    void RemovePlayer(int entityId);
    void UpdateHealing(int userId, const char *eventName);
    //void UpdateChargeLevel(int userId, const char *eventName);

    void LogUserMessage(int userId, const char *message);
    void LogEntityMessage(int entityId, const char *message);

    std::string GetPlayerString(int userId);

private:
    void LogPlayerMessage(Player *player, const char *message);
    int EntityIdToIndex(int entityId) { return entityId - 1; };
    Player *GetPlayer(int entityId);
    Player *GetPlayerByUserId(int userId);

private:
    IServerGameDLL      *mServer;
    IVEngineServer      *mEngine;
    IPlayerInfoManager  *mPlayerInfoManager;
    std::vector<Player> mPlayers;
    SendProps           *mSendProps;
};


PLUGIN_GLOBALVARS();

//extern VFunc<CBaseCombatWeapon * ( int )> CBasePlayer_Weapon_GetSlot;


#endif //_INCLUDE_ARSSTATS_STATS_H_